<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>押金管理</title>
</head>
<body class="easyui-layout">
<style type="text/css">
#cashTabs .a-Css{
    display: inline-block;
    border: 1px solid gray;
    background: #dee;
    padding: 2px 10px;
    border-radius: 5px;
    text-decoration: none;
    cursor: pointer;
	color: #d84242;
}
</style>
<script type="text/javascript" >
$(function(){
	initCash('');/* 押金统计的表格初始化 */
	
	//押金的搜索框
	$("#cashText").searchbox({
		searcher:function(value){
			initCash(value);
		}
	});
	
	//预交按钮弹框
	$("#payBoxBtn").click(function(){
		$(".popout").window("open");
	});
	
	//选项卡点击时刷新表格数据
	$("#cashTabs").tabs({
		onSelect:function(title){
			if(title=="押金记录"){
				$('#dealTable').datagrid('reload'); 
			}
		}
	}); 
	
	//预交确认按钮
	$("#payBtn").click(function(){
		$("#payForm").form({
			url:'ljw-cash-pay?i='+1,
			onSubmit:function(){
				return $(this).form('enableValidation').form('validate');
			},
			success:function(data){
				$('#cashTable').datagrid('reload'); 
				$("#payForm").form('clear');
				$(".popout").window("close");
			}
		});
		$("#payForm").submit();
	}); 
	//预交取消按钮
	$("#cancelBtn").click(function(){
		$("#payForm").form('clear');
		$(".popout").window("close");
	});
	
	initRocord("");//初始化押金记录
 
	//押金记录的搜索框
	$("#recordText").searchbox({
		searcher:function(value){
			initRocord(value);
		}
	});
	
	//打印完成按钮
	$("#alertOkBtn").click(function(){
		$(".alertWin").window("close");
	});
	
})
//押金记录表格的初始化方法
function initRocord(hid){
	$("#dealTable").datagrid({
		url:'ljw-cash-record?hid='+hid,
		fitColumns:true,
		pagination:true,
	    pageSize:10,
	    pageList:[5,10,20],
	    columns:[[
			{field:'hospital_id',title:'住 院 号',fixed:false,width:100,halign:'center'},
			{field:'bed_number',title:'床 位',fixed:false,width:50,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}		
			},
			{field:'patient_name',title:'姓 名',fixed:false,width:80,halign:'center'},
			{field:'patient_age',title:'年 龄',fixed:false,width:50,halign:'center'},
			{field:'patient_sex',title:'性 别',fixed:false,width:50,halign:'center'},
			{field:'cash_time',title:'交 易 时 间',fixed:false,width:200,align:'center',
				formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}	
			},
			{field:'cash_type',title:'交 易 类 型',fixed:false,width:70,halign:'center'},
			{field:'cash_money',title:'金 额',fixed:false,width:100,halign:'center',
				formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}		
			},
			{field:'cash_method',title:'交 易 方 式',fixed:false,width:80,halign:'center'},
			{field:'cash_name',title:'操 作 人',fixed:false,width:80,halign:'center'},
	    ]]
	});
}
//押金统计的表格
function initCash(hid){
	$("#cashTable").datagrid({
		url:'ljw-cash-total?hid='+hid,
		fitColumns:true,
		pagination:true,
	    pageSize:10,
	    pageList:[5,10,20],
	    columns:[[
			{field:'hospital_id',title:'住 院 号',width:110,halign:'center'},
			{field:'bed_number',title:'床 号',width:80,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}	
			},
			{field:'patient_name',title:'姓 名',width:100,halign:'center'},
			{field:'patient_age',title:'年 龄',width:80,halign:'center'},
			{field:'patient_sex',title:'性 别',width:60,halign:'center'},
			{field:'total',title:'累 计 押 金',width:120,halign:'center',
				formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}		
			},
			{field:'totalCash',title:'费 用 合 计',width:120,halign:'center',
				formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}		
			},
			{field:'balance',title:'押 金 余 额',width:120,halign:'center',
				formatter:function(value,row,index){
					var balance = (parseInt(row.total)-parseInt(row.totalCash));
					return "￥" + balance.toFixed(2);
				},
				styler: function (value, row, index) {
					if((parseInt(row.total)-parseInt(row.totalCash)) < 100){
			           	return 'color:#EC3D3D;';
					}
		        }
			},
			{field:'handle',title:'操 作',width:120,align:'center',
				formatter:function(value,row,index){
					if((parseInt(row.total)-parseInt(row.totalCash)) < 100){
						return "<a onclick='printWin("+row.hospital_id+")' class='a-Css'>打印催缴单</a>";
					}
				}
			}
	    ]],
	    onClickRow:function(index){//设置不可选中
			$(this).datagrid('unselectRow',index);
		}
	});
}

//打印催缴单
function printWin(hid){
	$(".alertWin").window("open");
	$.post(
		"ljw-cash-payment",
		{"hid":hid},
		function(data){
			console.log(data);
			console.log();
			$(".name").text(data[0].patient_name);
			$(".hid").text(data[0].hospital_id);
			$(".bed").text(data[0].bed_number);
			$(".totalCash").text(data[0].totalCash);
			$(".total").text(data[0].total);
			$(".dname").text(data[0].departments_name);
			var date = new Date(data[0].hospital_time);
			$(".year1").text(date.getFullYear());
			$(".month1").text(date.getMonth()+1);
			$(".day1").text(date.getDate());
			var date2 = new Date();
			$(".year2").text(date2.getFullYear());
			$(".month2").text(date2.getMonth()+1);
			$(".day2").text(date2.getDate());
		},"json"
	);
}

</script> 

<div class="easyui-tabs" id="cashTabs" fit="true" style="width: 100%;height: 100%;"> 
	<div title="押金统计" > 
		<div style="padding: 8px;background: #dee;">
			<input id="cashText" class="easyui-searchbox" data-options="prompt:'住院号/姓名查询'"> 
			<a class="easyui-linkbutton" id="payBoxBtn" style="padding:0 5px;margin: 0 20px;">预 交</a>
			<div style="padding: 10px;display: inline-block;float: right;font-size: 13px;margin-right: 30px;">
			 	<div style="background: #EC3D3D;border: 1px solid #ccc;display: inline-block;
			 			width: 22px;height: 9px;margin-right: 5px;">
			 	</div>
			 	余额不足
			</div>
		</div>
		<table id="cashTable" class="easyui-datagrid" style="width:100%; height:410px">
			
		</table>
		<!-- 打印弹框  Start -->
		<div class="easyui-window alertWin" title="体检报告" style="width:680px;user-select:none;"
			data-options="modal:true,collapsible:false,minimizable:false,
			maximizable:false,closed:true,draggable:false,shadow:true,resizable:false" style="padding:20px 40px">

			<div style="font-family: cursive;text-align: center;font-size: 16px;padding: 6px;border-bottom: 1px solid #CCC;height: 34px;line-height: 33px;font-size: 20px;">
				住院费用催缴通知单
			</div>
			<div style="font-size: 17px;font-family: cursive;height: 185px;line-height: 24px;">
				<p style="margin-bottom: 10px;">
					<span class="bed" style="font-weight: bolder;display: inline-block;margin-left: 12px;">
					</span>
					号床病人  
					<span class="name" style="font-weight: bolder;display: inline-block;">
					</span>
					 （住院号：  <span class="hid"></span>  ）：
				</p>
				<div style="display: inline-block;width: 30px"></div>
				  您自   <span class="year1"></span> 年  <span class="month1"></span> 月 <span class="day1"></span> 日在我科住院治疗至今
				（<span class="year2"></span> 年 <span class="month2"></span> 月 <span class="day2"></span>日），
				总计押金  <span class="total" style="font-weight: bolder;"></span> 元,
				产生费用总计  <span class="totalCash" style="font-weight: bolder;"></span>  元，可用押金余额已不足，
				请您尽快到收费处缴纳预交金 ，以免影响后续治疗，特此通知。
				<div style="text-align: right;padding-right: 40px;margin-top: 20px;margin-bottom: 5px;">
					平安医院住院部  <span class="dname"></span>
				</div>
				<div style="text-align: right;padding-right: 52px;">
					 <span class="year2"></span> 年 <span class="month2"></span> 月 <span class="day2"></span>日
				</div>
			</div>
			<div style="background: #dee;padding: 10px;text-align: center;">
				<a id="alertOkBtn" iconCls="icon-ok2" class="easyui-linkbutton" style="padding:0 5px;" id="opsBtn-ok">完成</a>
			</div>
		</div>
		<!-- 打印弹框  End-->
		
		<!-- 弹出层 -->
		<div class="easyui-window popout" title="预交押金"
		data-options="modal:true,collapsible:false,minimizable:false,
		maximizable:false,closed:true,draggable:false,shadow:true,resizable:false" style="padding:20px 40px">
			<form id="payForm" class="easyui-box" action="" method="post">
				<p>
					<input name="hospital.hospitalId" id="cash_Hid" class="easyui-textbox" required="required"
					 data-options="label:'住院号：',labelAlign:'right',width:260" /></p>
				<p>
					<select name="cashMethod" class="easyui-combobox" panelHeight="auto" editable="false" 
							data-options="label:'交易方式：',labelAlign:'right',width:160">
							<option selected="selected" value="现金">现金</option>
							<option value="微信">微信</option>
							<option value="支付宝">支付宝</option>
					</select>
				</p>
				<p>
					<input name="cashMoney" class="easyui-textbox" required="required" 
					data-options="label:'金额：',labelAlign:'right',width:200" />
				</p>
				<div style="margin: 0 auto;width:200px;text-align: center">
					<a id="payBtn" class="easyui-linkbutton" style="padding:0 5px;margin-right: 50px;">确定</a>
					<a id="cancelBtn" class="easyui-linkbutton" style="padding:0 5px;">取消</a>
				</div>
			</form>
		</div>
	</div> 
	
	<div title="押金记录" >
		<div style="padding: 8px;background: #dee;">
			<input id="recordText" class="easyui-searchbox" data-options="width:175,prompt:'住院号/姓名查询'"> 
		</div>
		<table id="dealTable" class="easyui-datagrid" style="height:410px">
			
		</table>
	</div>
	
</div>
</body>
</html>